package com.iflytek.topN;

import com.iflytek.top1.BestBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


public class BestTopNReducer extends Reducer<BestBean, LongWritable,BestBean,LongWritable> {
    @Override
    protected void reduce(BestBean key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        int num = 0;
        for (LongWritable value : values) {
            //输出每个类型最多的前3个
            if(num < 3){
                context.write(key,value);
                num++;
            }else {
                return;
            }
        }
    }
}